package someTestExcemple.huaweiOd.doublepointer;

//https://blog.csdn.net/guorui_java/article/details/137125845
//华为OD机试 - 绘图机器 - 双指针（Java 2025 A卷 100分）
import java.util.*;
public class DrawingMachines {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] line = Arrays.stream(sc.nextLine().split(" ")).
                mapToInt(Integer::parseInt).toArray();
        //n条指令，横坐标终点值E
        int N =line[0];
        int E =line[1];
        int[][] arrs = new int[N][2];
        for(int i=0;i<N;i++) {
            String[] lineArr = sc.nextLine().split(" ");
            int x = Integer.parseInt(lineArr[0]);
            int y = Integer.parseInt(lineArr[1]);
           arrs[i][0] = x;
           arrs[i][1] =y;

        }
        System.out.println(areaSum(arrs,E));

    }
    //核心解题思想：横坐标每前进一步，计算与上一步之间形成的正方形面积。
    public static int areaSum(int[][] arrs,int E) {
        int areaSum = 0;
        int leftX =arrs[0][0];
        int leftY =arrs[0][1];
        for(int i=1;i<arrs.length;i++) {
            int rightX = arrs[i][0];
            int rightY = arrs[i][1];
            areaSum +=(rightX-leftX)*Math.abs(leftY);
            leftX = rightX;
            leftY = leftY + rightY;
        }
        //最后一块面积别忘记算
        if(leftX < E) {
            areaSum +=(E-leftX)*Math.abs(leftY);
        }
        return areaSum;
    }
}

/**
 * 1、输入
 * 4 10
 * 1 -3
 * 3 2
 * 4 3
 * 6 -5
 *
 * 2、输出
 * 23
 */